package com.shu.domain.context;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by shu on 2017/9/8.
 */

public class DataSourceContextHolder {

    public static final Logger log = LoggerFactory.getLogger(DataSourceContextHolder.class);

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    // 设置数据源名
    public static void setDB(String dataSource) {
        log.info("切换到{}数据源", dataSource);
        contextHolder.set(dataSource);
    }

    // 获取数据源名
    public static String getDB() {
        return (contextHolder.get());
    }

    // 清除数据源名
    public static void clearDB() {
        contextHolder.remove();
    }


}
